package com.us.usws.site.console.resource;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;

import net.iwsh.core.exception.NoSuchObjectException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.us.usws.common.SiteConstants;
import com.us.usws.common.resourcetree.ResourceTreeHelper;
import com.us.usws.common.resourcetree.model.DefaultResourceTree;
import com.us.usws.support.uitls.SiteWebContext;
import com.us.usws.support.uitls.WebContext;

/**
 * User webservice
 */
@Path("/obj")
public class SysObjResource {

	private static Log log = LogFactory.getFactory().getInstance(SysObjResource.class);

	@GET
	@Path("/consoleMenu.json")
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	@Produces(MediaType.APPLICATION_JSON)
	public DefaultResourceTree getConsoleMenu(@Context HttpServletRequest request) {
		WebContext wc = new SiteWebContext(request, null);
		DefaultResourceTree ret;
		try {
			ret = ResourceTreeHelper.getConsoleMenuTree(SiteConstants.SYSOBJ_CONSOLE_MENU_OBJ_ID, wc.getUser());
		} catch (NoSuchObjectException e) {
			log.error("Get menu failure.", e);
			return failure();
		}
		return ret;
	}

	/**
	 * fail message
	 * @return
	 */
	private DefaultResourceTree failure() {

		return null;
	}

}
